clear 

use "$P_Data_Processed/monthly_station_data_e5_merged.dta"


merge 1:1 StID year_month using "$P_Data_Processed/mean_hourly_prices.dta"
keep if _merge==3
drop _merge

label variable mean_price_9 "Mean Price at 9am"
label variable mean_price_12 "Mean Price at Noon"
label variable mean_price_17 "Mean Price at 5pm"
label variable mean_price_19 "Mean Price at 7pm"


local i = 1

foreach var of varlist mean_price_9 mean_price_12 mean_price_17 mean_price_19 {
	
	capture drop outcome_var
	gener outcome_var = `var' 
	ivreghdfe `var'  n_act_stations n_mkt_compet_adopt l_gdp pop_density med_age employed_share l_pop n_brand mean_temp sd_temp mean_precip sd_precip  (treat = share_others_treated) if year<2019, absorb(year_month StID) cluster(mktid) 
	
	sum outcome_var if e(sample)==1 & treat_group==0
	scalar outcome_var_mean = r(mean)
	 
	if `i'==1 {	
		outreg2 using "$P_Tables/Table_E4",  tex(frag) dec(3) label addstat(Non-Adopter Mean Outcome,outcome_var_mean) replace nor2 keep(treat)
	}
	else {
		outreg2 using "$P_Tables/Table_E4",  tex(frag) dec(3) label addstat(Non-Adopter Mean Outcome,outcome_var_mean) append nor2 keep(treat)

		
	}

	local i = `i'+1
}
